package idv.arthur.jenkins;

import idv.arthur.widgets.Widgets;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.PostMethod;

public class TriggerJob {

	public static void main(String[] args) throws HttpException, IOException {
		final Widgets wid = new Widgets();
		final String jobName ="OL_BL_APadPjn2";
		final String urlStr =wid.JENKINSURL+"job/"+jobName+"/build?token="+jobName;
		final Map<String,Object> map = new HashMap<String,Object>();
        // 連線取得資料
		final PostMethod postMethod = new PostMethod(urlStr);
		postMethod.setRequestHeader("Content-type","application/xml; charset=UTF-8");
		
		final HttpClient client = new HttpClient();
		client.getParams().setAuthenticationPreemptive(true);
		client.getState().setCredentials( AuthScope.ANY, new UsernamePasswordCredentials(wid.JENKINS_USR,wid.JENKINS_PWD) );
		System.out.println(client.executeMethod(postMethod));

	}

}
